<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="../static/js/jquery-1.8.2.min.js"></script>
</head>
<body>
<div class="container">
    <input type="button" value="返回商品列表" class="btn btn-primary" id="back">
    <input type="button" value="查看我的砍价列表" class="btn btn-info" id="goOrder">
    <div align="center">
        <div><img src="" alt="" id="img" width="300px" height="300px"></div>
        <div style="color: red;font-size: 30px"><span id="goodsName"></span></div>
        <div style="font-size: 20px">原价:<span id="goodsPrice"></span>元,砍至最低价只要:<span id="floorPrice" style="font-size: 30px;color: red"></span>元,心动不如行动</div>
    </div>
    <div align="center">
        <input type="button" class="btn btn-success" value="就选它了" id="btn"></div>
</div>
</body>
<script>
    $.post(
        "/bargaining/echo",
        {"bargainingId":[[${param.bargainingId}]]},
        function (a) {
            $("#img").attr("src",a.goodsImg);
            $("#goodsName").html(a.goodsName);
            $("#goodsPrice").html(a.goodsPrice);
            $("#floorPrice").html(a.floorPrice);
        }
    )

    $("#btn").click(function () {
        $.post(
            "/order/addOrder",
            {"bargainingId":[[${param.bargainingId}]]},
            function (a) {
                if (a==1){
                    alert("选择成功，快来邀请好砍价吧");
                    location = "/order/goOrder";
                }else if (a==2){
                    alert("每个用户只能选择一个商品进行砍价");
                }else {
                    alert("失败");
                }
            }
        )
    })

    $("#back").click(function () {
        location = "/bargaining/bargainingList";
    })
    $("#goOrder").click(function () {
        $.post(
            "/order/findOrder",
            function (a) {
                if (a==0){
                    alert("您当前还没有选择任何商品");
                }else {
                    location = "/order/goOrder";
                }
            }
        )
    })
</script>
</html>
